package org.font
{
	import org.domain.BaseFont;

	public class FontWidthsStore
	{
		private static var store:Object;

		public static function getWidthsByFontName(baseFont:BaseFont):Object{
			if(store == null){
				store = createStore();
			}
			if(baseFont == null){
				baseFont = StandardFonts.helvetica;
			}
			return store[baseFont.fontName] as Object;
		}

		//Refactor: add other fonts width here. 
		//We can use the debugger to get the widths array from iText. 
		public static var helveticaWidthSource:String =     "750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 278 278 355 556 556 889 667 191 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015 667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667 778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 333 556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556 556 333 500 278 556 500 722 500 500 500 334 260 334 584 750 556 750 222 556 333 1000 556 556 333 1000 667 333 1000 750 611 750 750 222 222 333 333 350 556 1000 333 1000 500 333 944 750 500 667 278 333 556 556 556 556 260 556 333 737 370 556 584 333 737 333 400 549 333 333 333 576 537 278 333 333 365 556 834 834 834 611 667 667 667 667 667 667 1000 722 667 667 667 667 278 278 278 278 722 722 778 778 778 778 778 584 778 722 722 722 722 667 667 611 556 556 556 556 556 556 889 500 556 556 556 556 278 278 278 278 556 556 556 556 556 556 556 549 611 556 556 556 556 500 556 500";
		public static var helveticaBoldWidthSource:String = "750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 750 277 333 474 556 556 889 722 237 333 333 389 583 277 333 277 277 556 556 556 556 556 556 556 556 556 556 333 333 583 583 583 610 975 722 722 722 722 666 610 777 722 277 556 722 610 833 722 777 666 777 722 666 610 722 666 943 666 666 610 333 277 333 583 556 333 556 610 556 610 556 333 610 610 277 277 556 277 889 610 610 610 610 389 556 333 610 556 777 556 556 500 389 279 389 583 350 556 350 277 556 500 1000 556 556 333 1000 666 333 1000 350 610 350 350 277 277 500 500 350 556 1000 333 1000 556 333 943 350 500 666 277 333 556 556 556 556 279 556 333 736 370 556 583 333 736 552 399 548 333 333 333 611 556 277 333 333 365 556 833 833 833 610 722 722 722 722 722 722 1000 722 666 666 666 666 277 277 277 277 722 722 777 777 777 777 777 583 777 722 722 722 722 666 666 610 556 556 556 556 556 556 889 556 556 556 556 556 277 277 277 277 610 610 610 610 610 610 610 548 610 610 610 610 610 556 610 556";

		public static function createWidthsByName(helveticaWidthSource:String):Object{
			var widthItems:Array = helveticaWidthSource.split(" ");
			var widths:Object = new Object();
			for(var i:int = 0 ; i < 256 ; i++){
				widths[String.fromCharCode(i)] = Number(widthItems[i]); 
			}
			return widths;
		}

		public static function createStore():Object{
			store = new Object();
			store[StandardFonts.helvetica.fontName] = createWidthsByName(helveticaWidthSource);
			store[StandardFonts.helveticaBold.fontName] = createWidthsByName(helveticaBoldWidthSource);
			return store;
		}



	}
}




